package com.jm.utils.htmlNode;


import org.htmlparser.nodes.TagNode;
import org.htmlparser.nodes.TextNode;

import com.jm.utils.StringHelper;


/**
 * @author yanjie
 * Oct 28, 2011 10:55:56 AM
 */
public class TgNode extends BaseNode{
	protected TagNode node = null ;
	
	@Override
	public void onInit(Object node) {
		super.onInit(node);
		this.node = (TagNode)node;
	}
	
	@Override
	public void loadConfig() {
		super.loadConfig();
		
		if(node != null){
			//名稱
			this.setNodeName(StringHelper.getValue(node.getTagName()).trim().toLowerCase());
			
			//節點值 沒有
			
			//屬性
			if(node.getAttributes() != null){
				this.setAttributes(node.getAttributes());
//				System.out.println("-----------"
//						+ node.getAttributes().containsKey("$<TAGNAME>$"));
//				node.getAttributes().remove("$<TAGNAME>$");
//				Hashtable attrs = new Hashtable(); 
//				for(Iterator it = node.getAttributes().keySet().iterator();it.hasNext();){
//					String key = (String)it.next();
//					System.out.println(key+"---------"+node.getAttributes().get(key));
//				}
				//this.setAttributes();
			}
			
			//子節點
			if(node.getChildren() != null){
				if(node.getChildren().size() == 1 && node.getChildren().elementAt(0) instanceof TextNode){
					TextNode txNode = (TextNode)node.getChildren().elementAt(0);
					this.setNodeValue(txNode.getText());
				}else{
					NodeList nodeList = new NodeList();
					nodeList.fromNodeList(node.getChildren(),this.getPage());
					if(nodeList.size() >0)
						this.setChildNodes(nodeList);
				}
			}
		}
	}
	
}
